package org.example;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.example.entity.Product;

import java.io.IOException;

/**
 * @Author : 叶荻风
 * @create : 2024/6/5 20:10
 */

public class ElasticClient {
    public static void main(String[] args) throws IOException {

    }

    public static ElasticsearchClient getClient(){
        // URL and API key
        String serverUrl = "http://localhost:9200";

// Create the low-level client
        RestClient restClient = RestClient
                .builder(HttpHost.create(serverUrl))
                .build();
// Create the transport with a Jackson mapper
        ElasticsearchTransport transport = new RestClientTransport(
                restClient, new JacksonJsonpMapper());
// And create the API client

        return new ElasticsearchClient(transport);
    }
}
